package com.shatower.chatctrl.controller;


import com.shatower.chatctrl.result.Result;

import java.util.List;

/**
 * @description：基础 controller
 */
public abstract class BaseController {

    /**
     * ajax失败
     * @param msg 失败的消息
     * @return {Object}
     */
    public Object renderError(String msg) {
        Result result = new Result();
        result.setMsg(msg);
        return result;
    }

    /**
     * ajax成功
     * @return {Object}
     */
    public Object renderSuccess() {
        Result result = new Result();
        result.setCode(Short.valueOf("0"));
        return result;
    }

    /**
     * ajax成功
     * @param msg 消息
     * @return {Object}
     */
    public Object renderSuccess(String msg) {
        Result result = new Result();
        result.setCode(Short.valueOf("0"));
        result.setMsg(msg);
        return result;
    }


    /**
     * ajax成功
     * @param obj 成功时的对象
     * @return {Object}
     */
    public Object renderSuccess(Object obj) {
        Result result = new Result();
        result.setCode(Short.valueOf("0"));
        result.setObj(obj);
        return result;
    }

    /**
     * 检查对象是否是空
     *
     * @return
     */
    public static boolean isNullOrEmpty(Object o) {
        if (o instanceof List) {
            if (((List) o).size() <= 0) {
                return false;
            }
        }
        if (o == null) {
            return false;
        }
        if (o.equals("")) {
            return false;
        }
        if (o == "") {
            return false;
        }


        return true;
    }
}
